package com.pig4cloud.pig.village.rules.generator.conditions;

import com.pig4cloud.pig.village.rules.RuleCondition;

public class NumericRangeParser extends AbstractConditionParser {

	/**
	 * Parse numeric range
	 * Input: key is age, value is "x > 90 || x < 10".
	 * Output: (age > 90 || age < 10)
	 * @param ruleCondition ruleCondition
	 * @return
	 */
	public StringBuilder parse(RuleCondition ruleCondition) {
		StringBuilder subConditionBuilder = new StringBuilder("(");
		// Parse from "x<90" to "age<90"
		String replacedConditionValue = ruleCondition.getConditionValue()
				.replaceAll("[x]", ruleCondition.getConditionKey());
		subConditionBuilder.append(replacedConditionValue).append(")");
		return subConditionBuilder;
	}
}